import { apiService } from "@service/index";

export const searchEndpoints = apiService.injectEndpoints({
  endpoints: (build) => ({
    // 获取搜索关键字的联想建议
    requestSuggestion: build.query<SuggestionResponse, string>({
      query: (q) => ({ url: "/suggestion", params: { q } }),
    }),
    // 获取搜索结果
    requestSearchResult: build.query<
      SearchResultResponse,
      { page: number; per_page: number; q: string }
    >({
      query: (params) => ({ url: "/search", params }),
    }),
  }),
});

export const {
  useLazyRequestSuggestionQuery,
  useLazyRequestSearchResultQuery,
} = searchEndpoints;
